<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: Help.php 362 2010-02-03 08:41:11Z steen.rabol@gmail.com $
 *
 */

Prado::using('Application.Common.Data.PortalHelpRecord');

class Help extends PortalSystemPage
{
	private $_helpRec = null;

	public function getHelpRecord()
	{
		if($this->_helpRec === null)
		{
			$this->_helpRec	= PortalHelpRecord::finder()->findBypagename_AND_culture($this->Request['pagename'],$this->Application->Culture);
		}

		return $this->_helpRec;
	}

	public function onInit($param)
	{
		parent::onInit($param);

		if(!$this->User)
		{
			$this->reportError(1,Prado::localize("You need to be logged in to use this page"));
		}

		if($this->User->RoleId != $this->Application->Parameters['AdminRole'])
		{
			$this->reportError(1,Prado::localize("You do not have access to this function/page"));
		}
	}

	public function onLoad($param)
	{
		parent::onLoad($param);

		$this->Page->Title = Prado::localize("Help") . ' - ' . $this->Request['pagename'];
		if($this->HelpRecord !== null)
		{
			$this->HelpContent->Text		= $this->HelpRecord->content;
			$this->HelpGrp->GroupingText	= $this->HelpRecord->title;
		}
		else
		{
			// Show TOC
			$this->HelpContent->Text		= Prado::localize("No help for this page '{0}' in your language '{1}'",array($this->Request['pagename'],$this->Application->Culture));
			$this->HelpGrp->GroupingText	= Prado::localize("Help");
		}
	}

	public function getEditUrl()
	{
		return $this->Service->constructUrl('System.HelpEdit',array('pagename' => $this->Request['pagename']));
	}
}
?>